using NUnit.Framework;
using RMH.DataAccess;
using RMH.Entities;
using RMH.UnitTests;
using RMH.Web;
namespace RMH.IntegrationTests.Repository
{
    [TestFixture]
    public class StayRepository_when_persisting : base_test
    {
        private Stay stay = new Stay {HospitalUnit = "Asd", CheckinBy = "Foo", CheckoutBy = "Foo"};
        private Patient patient;
        private Room room;
        private Payment payment;

        private StayRepository stayRepository = Container.Resolve<StayRepository>();
        public override void establish_context()
        {
            patient = Container.Resolve<PatientRepository>().GetFirst();
            room = Container.Resolve<RoomRepository>().GetFirst();
            Check.Require(patient, "You are not testing anything.");
            Check.Require(room, "You are not testing anything.");
            stay.Patient = patient;
            stay.Room = room;
            payment = new Payment { Amount = 22.22, Method = PaymentMethod.Check, Type = PaymentType.SelfPay };
            stay.Payment = payment;
            base.establish_context();
        }

        public override void because()
        {
            stayRepository.Save(stay);
            stayRepository.Flush();
            stayRepository.Clear();
            stay = stayRepository.GetByID(stay.Id);
        }

        [Test]
        public void Patient_is_persisted()
        {
            stay.Patient.ShouldEqual(patient);
        }

        [Test]
        public void Room_is_persisted()
        {
            stay.Room.ShouldEqual(room);
        }

        [Test]
        public void CheckIn_Person_is_persisted()
        {
            stay.CheckinBy.ShouldEqual("Foo");
        }

        [Test]
        public void CheckOut_Person_is_persisted()
        {
            stay.CheckoutBy.ShouldEqual("Foo");
        }

        [Test]
        public void Payment_is_persisted()
        {
            stay.Payment.ShouldEqual(payment);
        }

    }
}